<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>数据库交互</title>
    <!-- Bootstrap -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

  </head>
  <body>
  <h1>数据列表</h1>
  <form action= "c.php" method = "get">
  <button class="btn btn-lg btn-default" type="submit">添加</button>


 <?php
header("content-type:text/html;charset=utf-8");

$hostname = "127.0.0.1";
$username = "root";
$password = "root";
$database = "pro";

$connection = mysql_connect($hostname,$username,$password) or exit(mysql_error());//连接数据库

mysql_query("set names 'utf8'");//设置字符集

mysql_select_db($database,$connection) or exit(mysql_error());//选择数据库
?>

	<table class="table table-bordered">
	   <thead>
	   <tr>
				<th>ID</th>
				<th>名称</th>
				<th>标题</th>
				<th>类型</th>
				<th>价格</th>
				<th>操作</th>
		</tr>
		</thead>
		<tbody>

<?php
$result = mysql_query("select * from product");//执行sql语句
$list = array();
while($tmp=mysql_fetch_array($result,MYSQL_ASSOC)){
$list[] = $tmp; 
}
?>

<?php 
foreach ($list as $k=>$v){?>
      <tr>
         <td><?php echo $v['id'];?></td>
         <td><?php echo $v['named'];?></td>
         <td><?php echo $v['title'];?></td>
         <td><?php echo $v['type'];?></td>
         <td><?php echo $v['price'];?></td>
         <td><a href="a.php?id=<?php echo $v['id'];?>"><span class="label label-info">修改</span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="b.php?id=<?php echo $v['id'];?>"><span class="label label-danger">删除</span></a></td>
      </tr>
      </tbody>
<?php }?>
</table>

<?php
mysql_close($connection);//关闭数据连接
?>






 